import os
import sys

sys.path.append(os.path.abspath(os.path.join(os.getcwd(), "../")))

from src.View import View
from src.EventBus import EventManager, Event
from src.FileMonitor import FileMonitor


def stop_work(evt):
    event_mgr.stop()
    monitor.stop()


if __name__ == '__main__':
    monitor = FileMonitor()
    event_mgr = EventManager()

    view = View()
    view.pre_draw()
    EventManager.add_event_listener(Event.ON_APPLICATION_CLOSE, stop_work)
    EventManager.add_event_listener(Event.ON_FRAME_UPDATE, view.draw)

    event_mgr.start()

    monitor.start()

    try:
        event_mgr.run()
    except KeyboardInterrupt:
        print('Key interrupt, Stop event looping.')

    monitor.stop()

    print('Finished.')
